package com.sunrise.visual.frame.common
{
	import mx.controls.Alert;

	public class Gauge
	{
		public var config:Object;
		public var data:String;
		public function  Gauge(data:String,config:Object)
		{   
			
			this.data = data;
			this.config = config;
		}
		
		public  function parseXML():XML {
			
			var minValue:String=this.config.minValue||"0";
			var colorValue1:String=this.config.colorValue1||"30";
			var colorValue2:String=this.config.colorValue2||"50";
			var maxValue:String=this.config.maxValue||"100";
			var value:String=this.data||"0";
			var minV:Number=parseFloat(minValue);
			var cv1:Number=parseFloat(colorValue1);
			var cv2:Number=parseFloat(colorValue2);
			var maxV:Number=parseFloat(maxValue);
			var v:Number=parseFloat(value);
			var color:String="";
			var colorList:Array = config.colors || ["green","yellow","red"];
			if(v>=minV&&v<=cv1){
				color=colorList[0];
			}else if(v>cv1&&v<=cv2){
				color=colorList[1];
			
			}else {
				color=colorList[2];
			
			}
			this.config.color=color;
			var xml:XML =this.getXML();
			
			return xml;
		}
		private function getXML():XML{
			var colorList:Array = config.colors || ["green","yellow","red"];
			
			var xml:XML =<anychart>
  <margin all="0"/>
 <settings>
<animation enabled="True" />
</settings>

  <gauges>
    <gauge>
      <chart_settings>
			<chart_background enabled="false">
			      <inside_margin left="0" top="0" right="0" bottom="0"/>
			</chart_background>
			<data_plot_background enabled="false"/>
			<title enabled="false">
			</title>
      </chart_settings>
	  
      <circular>
	  
        <axis radius="50" start_angle="70" sweep_angle="220">
          <scale minimum="0" maximum="100" major_interval="10" />
          <scale_bar enabled="true">
            <fill type="solid" color="#000000" opacity="1"/>
          </scale_bar>
		  
          <major_tickmark enabled="true" shape="Trapezoid" width="3" length="10">
            <fill color="white"/>
            <border enabled="true" color="white"/>
            <effects enabled="true">
              <bevel enabled="true" distance="1"/>
            </effects>
          </major_tickmark>
		  
          <labels enabled="true" align="Inside" padding="6" rotate_circular="true" auto_orientation="false" >
            <format><![CDATA[{%Value}{numDecimals:0}]]></format>
<font family="Microsoft Yahei"  color="White" size="12" bold="false">
              <effects enabled="true">
                <drop_shadow enabled="true"/>
              </effects>
            </font>
          </labels>
		  
		  <color_ranges >
			<color_range start={this.config.minValue||"0"} end={this.config.colorValue1||"30"} color={colorList[0]} start_size="12" end_size="12" padding="0"/>
			<color_range start={this.config.colorValue1||"30"} end={this.config.colorValue2||"50"} color={colorList[1]} start_size="12" end_size="12" padding="0"/>
			<color_range start={this.config.colorValue2||"50"} end={this.config.maxValue||"100"}  color={colorList[2]} start_size="12" end_size="12" padding="0"/>
			
		 </color_ranges >
         
		  
        </axis>
		
		
        <frame type="Auto" >
          <outer_stroke enabled="false"/>
		  
          <inner_stroke thickness="8">
            <border enabled="true" color="white" opacity="0.1"/>
            <fill type="Solid" color="white"/> <!--//此处是设置边框颜色 -->
          </inner_stroke>
		  
          <background>
            <fill type="Gradient" enabled="false">
              <gradient angle="-45">
                <key color="#1B1B1B"/>
                <key color="#4B4A4B"/>
              </gradient>
            </fill>
          </background>
		  
		  
          <effects enabled="true">
            <glow enabled="true" color="White" blur_x="10" blur_y="10" opacity="0.7"/>
          </effects>
		  
        </frame>
        <pointers>
		
		<pointer type="Needle" value={this.data||"0"} color={this.config.color}>
            <tooltip enabled="true"/>
            <needle_pointer_style name="defaultWithDarkCap">
              <cap enabled="true" radius="10">
                <background enabled="true">
                  <fill type="Gradient">
                    <gradient type="Radial">
                      <key color="#666666" position="0"/>
                      <key color="#666666" position="0.7"/>
                      <key color="#292929" position="1"/>
                    </gradient>
                  </fill>
                </background>
              </cap>
            </needle_pointer_style>
			<label enabled="true" under_pointers="true">
			<format>
			<![CDATA[ {%Value}{numDecimals:2}]]>
			</format>
			<position placement_mode="ByPoint" x="50" y="50" valign="Center" halign="Center"/>
<font family="Microsoft Yahei" color="#000000" bold="false" size="12">
			</font>
			<background enabled="true">
			<fill type="Gradient" >
			<gradient>
			<key color="white"/>
			<key color="white"/>
			<key color="white"/>
			</gradient>
			</fill>
			<corners type="Rounded" all="3"/>
			<border enabled="false"/>
			<effects enabled="true">
			<inner_shadow enabled="false" distance="2"/>
			</effects>
			</background>
			</label>
            <animation enabled="true" start_type="0" duration="0.7" interpolation_type="Bounce"/>
          </pointer>
		  
        </pointers>
      </circular>
    </gauge>
  </gauges>
</anychart>;
				
				
			return xml;
		}
	}
}